package com.lc.cehui.ui.fragment.home;

import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.lc.cehui.R;
import com.lc.cehui.app.AppFragment;
import com.lc.cehui.http.response.CompanyInfoBean;
import com.lc.cehui.http.response.TechnologyShowBean;
import com.lc.cehui.other.IntentKey;
import com.lc.cehui.ui.activity.home.TrainingDetailsActivity;
import com.lc.cehui.util.SPUtil;
import com.lcodecore.tkrefreshlayout.utils.LogUtil;

import butterknife.BindView;

public class TrainingDetailsFragment extends AppFragment<TrainingDetailsActivity> {
    @BindView(R.id.webView)
    WebView webView;
    private TechnologyShowBean data;
    private String newsTextSrart = "<html>" +
            "<head>" +
            "<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0'>" +
            "</head>" +
            "<body>";

    private String newsTextEnd = "<style type=\"text/css\"> img {" +
            "width: 100% !important;" +
            "height:auto !important;" +
            "}" +
            "</style>" +
            "</body></html>";
    @Override
    protected int getLayoutId() {
        return R.layout.fragment_trainingdetails;
    }

    @Override
    protected void initView() {
        Gson gson = new Gson();
        data = gson.fromJson(SPUtil.get(getContext(), IntentKey.TEXT,""), new TypeToken<TechnologyShowBean>() {
        }.getType());
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webSettings.setUseWideViewPort(true);//设置webview推荐使用的窗口
        webSettings.setLoadWithOverviewMode(true);//设置webview加载的页面的模式
        webSettings.setDisplayZoomControls(false);//隐藏webview缩放按钮
        webSettings.setJavaScriptEnabled(true); // 设置支持javascript脚本
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {

                LogUtil.i("webview加载结束");
            }
        });
        webView.loadDataWithBaseURL(null, newsTextSrart + data.getData().getContent() + newsTextEnd
                , "text/html", "UTF-8", null);
    }

    @Override
    protected void initData() {

    }
}
